package fr.playsoft.psas.parcel;

import java.util.ArrayList;
import java.util.List;

import android.os.Parcel;
import android.os.Parcelable;

public class ComplexObj1 implements Parcelable {
	
	public String title;
	public ArrayList<SimpleObj> items;
	
	public ComplexObj1() {};
	
	public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
		public ComplexObj1 createFromParcel(Parcel in) {
			return new ComplexObj1(in); 
		}
		public ComplexObj1[] newArray(int size) {
			return new ComplexObj1[size];
		}
	};
	
	@Override
	public int describeContents() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeString(title);
		dest.writeTypedList(items);
	}
	
	private ComplexObj1(Parcel in) { readFromParcel(in);  }

	private void readFromParcel(Parcel in) {
		title = in.readString();
		if(items == null)
			items = new ArrayList<SimpleObj>();
		in.readTypedList(items, SimpleObj.CREATOR);
	}
	
	public String[] toArrString() {
		String[] retArr = new String[items.size() + 1];
		retArr[0] = title;
		
		for(int i = 0; i < items.size(); i++)
			retArr[i+1] = items.get(i).toString();
		
		return retArr;
	}

}
